#include "my_map.h"
#include <iostream>
#include <string>
#include <thread>

static my_map<int, std::string> m;
static std::vector<int> v;

static void prepareData() {
	m.add_or_update_mapping(1, "chat");
	m.add_or_update_mapping(2, "souris");
	m.add_or_update_mapping(3, "poisson");
	m.add_or_update_mapping(4, "elephant");
	m.add_or_update_mapping(5, "dauphin");
	m.add_or_update_mapping(6, "baleine");
	m.add_or_update_mapping(7, "pigeon");
	m.add_or_update_mapping(8, "lion");
	m.add_or_update_mapping(9, "panthere");
	m.add_or_update_mapping(10, "tigre");
	m.add_or_update_mapping(11, "hippopotame");
	m.add_or_update_mapping(12, "araignee");
	m.add_or_update_mapping(13, "papillon");
	m.add_or_update_mapping(14, "girafe");
	m.add_or_update_mapping(15, "cochon");
	m.add_or_update_mapping(16, "boeuf");
	m.add_or_update_mapping(17, "singe");
	m.add_or_update_mapping(18, "aigle");
	m.add_or_update_mapping(19, "cheval");
	m.add_or_update_mapping(20, "ane");
	m.add_or_update_mapping(21, "chameau");
	m.add_or_update_mapping(22, "crocodile");
	m.add_or_update_mapping(23, "grenouille");
	v.push_back(11);
	v.push_back(5);
	v.push_back(8);
	v.push_back(19);
	v.push_back(32);
	v.push_back(16);
	v.push_back(24);
	v.push_back(26);
	v.push_back(3);
	v.push_back(10);
	v.push_back(31);
}

static void thread1() {
	for (int i : v) {
		m.remove(i);
	}
}

static void thread2() {
	m.add_or_update_mapping(24, "cigale");
	m.add_or_update_mapping(25, "cygne");
	m.add_or_update_mapping(26, "corbeau");
	m.add_or_update_mapping(27, "coq");
	m.add_or_update_mapping(28, "hibou");
	m.add_or_update_mapping(29, "loup");
	m.add_or_update_mapping(30, "serpent");
}

static void thread3() {
	m.add_or_update_mapping(31, "renard");
	m.add_or_update_mapping(32, "ours");
	m.add_or_update_mapping(33, "lapin");
	m.add_or_update_mapping(34, "tortue");
}

static void thread4() {
	for (int i = 0; i < my_map<int, std::string>::NB_BUCKETS_DEFAUT; i++) {
		std::cout << "Bucket " << i << " : " << std::endl;
		typename bucket<int, std::string>::bucket_data data = m.getBucketIndex(i).getData();
		for (typename bucket<int, std::string>::bucket_iterator it = data.begin(); it != data.end(); it++) {
			std::cout << it->first << " : " << it->second << std::endl;
		}
		std::cout << std::endl;
	}
}

int main(int argc, char** argv) {
	prepareData();
	std::thread t2(thread2);
	std::thread t1(thread1);
	std::thread t3(thread3);
	t2.join();
	t1.join();
	t3.join();
	std::thread t4(thread4);
	t4.join();
	return 0;
}
